﻿<?php
class wt_xml
{
	#将RSS内博客信息相关信息存入数组$arr
	function S_xml2arr($xmlfile)
	{
		$xml = simplexml_load_file($xmlfile);
		foreach($xml -> children() as $child)
		{
			$arr["title"] = (string)($child -> title);
			$arr["lastBuildDate"] = (string)($child -> lastBuildDate);
			$arr["link"] = (string)($child -> link);
			$arr["description"] = (string)($child -> description);
		}
		return $arr;
	}
}
/*
function S_xml2arr($xmlfile)
{
	$xml = simplexml_load_file($xmlfile);
	//$arr = array();
	foreach($xml -> children() as $child)
	{
		$arr["title"] = (string)($child -> title);
		$arr["lastBuildDate"] = (string)($child -> lastBuildDate);
		$arr["link"] = (string)($child -> link);
		$arr["description"] = (string)($child -> description);
	}
	return $arr;
}*/

$arr = S_xml2arr("feed.xml");
print_r ($arr);

#打开MYSQL连接t
$link = mysql_connect("localhost","root","tto123");
if(!$link)
{
	#die("不能打开连接" . mysql_error());
	echo ("dfsfs");
}
mysql_select_db("feed",$link);
//$sql = "INSERT INTO `blog_info` (`BID` , `Blog_Title` , `Blog_Descripton` , `Blog_LastBuildDate`) VALUES (NULL ,`" . $arr['title'] . "`,`" . $arr['link'] . "`,`" . $arr['description'] . "`,`" . $arr['LastBuildDate'] . "`)";
$sql = "
INSERT INTO `feed`.`blog_info` (
`BID` ,
`Blog_Title` ,
`Blog_Link` ,
`Blog_Descripton` ,
`Blog_LastBuildDate` 
)
VALUES (
NULL , '" . $arr["title"] . "', '" . $arr["link"] . "', '" . $arr["description"] . "', '" . $arr["lastBuildDate"] . "'
);
";
mysql_query($sql) or die("Invalid query: " . mysql_error());

